package com.collect.zambia.zhiScene.zhiAuditer.zhiFollow.zhiCollect;

import android.content.Context;

import com.collect.zambia.zhiBase.BasePresenter;
import com.collect.zambia.zhiBase.BaseSubscriber;
import com.collect.zambia.zhiBean.zhiReceive.ZHIRCaseListEntity;
import com.collect.zambia.zhiBean.zhiSend.ZHISDailyCaseEntity;
import com.collect.zambia.zhiNetApi.ZHIHttpApiProvider;
import com.collect.zambia.zhiNetApi.ZHIHttpResponse;
import com.collect.zambia.zhiUtils.RxSchedulers;

import javax.inject.Inject;

public class ZHIAuditerCollectPresenter extends BasePresenter<ZHIAuditerCollectContract.View> implements ZHIAuditerCollectContract.Presenter {

    @Inject
    public ZHIAuditerCollectPresenter() {

    }

    @Override
    public void getLatestCaseListV2(Context context, final ZHISDailyCaseEntity zhisDailyCaseEntity, boolean showLoading) {
        BaseSubscriber<ZHIHttpResponse<ZHIRCaseListEntity>> subscriber = new
                BaseSubscriber<ZHIHttpResponse<ZHIRCaseListEntity>>(context, this, showLoading) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            ZHIRCaseListEntity caseListEntity = (ZHIRCaseListEntity) object;
                            mView.onGetLatestCaseListV2(caseListEntity);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().caseListV2(zhisDailyCaseEntity)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }
}
